package sysLearn;

/**
 * @program: planet-company
 * @description:
 * @author: jyz
 * @create: 2019-08-29 20:55
 **/
public class TestB {

    public static synchronized void method1(){
      System.out.println("Method 1 start");
       try {
            System.out.println("Method 1 execute");
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                 e.printStackTrace();
            }
            System.out.println("Method 1 end");
    }

    public static synchronized void method2(){
        System.out.println("Method 2 start");
        try {
            System.out.println("Method 2 execute");
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Method 2 end");
    }


    public static void main(String[] args) {
        final TestB test = new TestB();
        final TestB test2 = new TestB();


        new Thread(new Runnable() {
        @Override
        public void run() {
            test.method1();
        }}).start();


        new Thread(new Runnable() {
        @Override
        public void run() {
            test2.method2();
        }}).start();
    }

}
